package com.sanbuTech.foundation.db;

public class DBContextHolder {
	/**
	 * 线程threadlocal
	 */
	private static ThreadLocal<String> contextHolder = new ThreadLocal<>();

	public static String DataSourceRead = "dataSourceRead";
	public static String DataSourceWrite = "dataSourceWrite";

	/**
	 * 获取数据库类型
	 * @return
	 */
	public static String getDbType() {
		String db = contextHolder.get();
		if (db == null) {
			db = DataSourceWrite;// 默认是读写库
		}
		return db;
	}

	/**
	 * 
	 * 设置本线程的数据库类型
	 * 
	 * @param str
	 */
	public static void setDbType(String str) {
		contextHolder.set(str);
	}

	/**
	 * clearDBType
	 * 
	 * @Description: 清理数据库类型
	 */
	public static void clearDBType() {
		contextHolder.remove();
	}
}
